package com.haojii.jdo;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.haojii.jdo.orm.one2many.DeliveryAddress;
import com.haojii.jdo.orm.one2many.User;
import com.haojii.jdo.utils.PMF;

@SuppressWarnings("serial")
public class One2ManyServlet2 extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("text/plain");
		PersistenceManager pm = PMF.get().getPersistenceManager();
		
		User u = new User();
		
		DeliveryAddress d1 = new DeliveryAddress();
		d1.setAddress("d1 address");
		d1.setCity("SH");
		d1.setPhoneNumber("137XXXXXXXX");
		d1.setZip("200335");
		d1.setUser(u);
		DeliveryAddress d2 = new DeliveryAddress();
		d2.setAddress("d2 address");
		d2.setCity("BJ");
		d2.setPhoneNumber("138XXXXXXXX");
		d2.setZip("100335");
		d2.setUser(u);
		//pm.makePersistent(d1);
		//pm.makePersistent(d2);
		
		List<DeliveryAddress> addressList = new ArrayList<DeliveryAddress>();
		addressList.add(d1);
		addressList.add(d2);
		u.setAddressList(addressList);
		
		pm.makePersistent(u);
		resp.getWriter().println("Hello, world");
	}
}
